<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100间的数字" id="i1">
<input type="button" value="猜一猜" onclick="f()">
<div></div>

<script>
    let x = parseInt(Math.random()*100)+1;
    let d =document.querySelector("div");
    d.innerText = x;
    let num = 0;
    function f(){
        num++;
        if(i1.value<x){
            d.innerText="猜小了";
        }else if(i1.value>x){
            d.innerText="猜大了";
        }else{
            d.innerText="猜对了!你一共猜了"+num+"次!"
        }
    }

</script>
</body>
</html>